package com.cs.dingdingauto

import android.app.Activity
import android.app.Application
import android.content.Context
import android.os.Bundle
import android.util.Log
import com.cs.dingdingauto.extent.ExternalActivityUtil


/**
 * @author liguandong
 * @data 2023/7/4
 *
 */
class MyApplication : Application() {
    companion object{
        private const val TAG = "lgd"
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        ExternalActivityUtil.attachBaseContext(baseContext = base!!,this,false)
    }

    override fun onCreate() {
        super.onCreate()
        registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                Log.i(TAG, "onActivityCreated: ${activity.javaClass.name}")
            }

            override fun onActivityResumed(activity: Activity) {
                Log.i(TAG, "onActivityResumed: ${activity.javaClass.name}")
            }

            override fun onActivityPaused(activity: Activity) {
                Log.i(TAG, "onActivityPaused: ${activity.javaClass.name}")
            }

            override fun onActivityStarted(activity: Activity) {
                Log.i(TAG, "onActivityStarted: ${activity.javaClass.name}")
            }

            override fun onActivityStopped(activity: Activity) {
                Log.i(TAG, "onActivityStopped: ${activity.javaClass.name}")
            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
                
            }

            override fun onActivityDestroyed(activity: Activity) {
                Log.i(TAG, "onActivityDestroyed: ${activity.javaClass.name}")
            }
        })
        DingDingHelper.init(applicationContext)

        //        val uploadWorkRequest: WorkRequest =
        //            OneTimeWorkRequestBuilder<DingDingWork>()
        //                .build()

        //        val dingdingRequest =
        //            PeriodicWorkRequestBuilder<DingDingWork>(15, TimeUnit.MINUTES)
        //                // Additional configuration
        //                .build()
        //        WorkManager.getInstance(applicationContext).cancelUniqueWork("dingdingRequest")
        //        WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(
        //            "dingdingRequest",
        //            ExistingPeriodicWorkPolicy.UPDATE,
        //            dingdingRequest)
        //
        //        val launchRequest =
        //            PeriodicWorkRequestBuilder<LaunchAppWork>(15, TimeUnit.MINUTES)
        //                // Additional configuration
        //                .build()
        //        WorkManager.getInstance(applicationContext).cancelUniqueWork("launchRequest")
        //        WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(
        //            "launchRequest",
        //            ExistingPeriodicWorkPolicy.UPDATE,
        //            launchRequest)


    }

}